<template>
  <div class="search-list">
    <transition-group name="list" tag="ul">
      <li
        v-for="item in searches"
        :key="item"
        class="search-item"
        @click="selectItem(item)"
      >
        <span class="text">{{item}}</span>
        <span
          v-if="showDelete"
          class="icon1"
          @click.stop="deleteItem(item)"
        >
          <i class="icon iconfont icon-clear-num"></i>
        </span>
      </li>
    </transition-group>
  </div>
</template>

<script>
  export default {
    name: 'search-list',
    props: {
      searches: {
        type: Array,
        default() {
          return []
        }
      },
      showDelete: {
        type: Boolean,
        default: true
      }
    },
    emits: ['select', 'delete'],
    methods: {
      selectItem(item) {
        this.$emit('select', item)
      },
      deleteItem(item) {
        this.$emit('delete', item)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .search-list {
    .search-item {
      display: flex;
      align-items: center;
      height: 40px;
      overflow: hidden;
      .text {
        flex: 1;
        font-size: 14px;
      }
      .icon1 {
        @include extend-click();
        .icon-clear-num {
          font-size: 12px;
          color: $theme-color;
        }
      }
    }
  }
</style>
